Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make relay type fields extendable #1499

Merged
merged 5 commits into from
Mar 13, 2023

Conversation

erikwrede
Copy link
Member

@erikwrede erikwrede commented Mar 2, 2023

This PR enables users to easily modify the relay.Connection type to add fields like nodes, or customize the existing Edges and PageInfo fields to make changes about nullability.
This is handy for cases like having a generic nodes field, that skips the use of edges for non-pagination use. The change is enabled by checking if _meta was already provided in the keyword arguments of Node/Connection's init_subclass_with_meta, so we don't override existing field definitions from the superclass.

The most common use case will be to add a generic nodes field for cases where cursor-based pagination is not necessary:

type MyTypeConnection {
	pageInfo: PageInfo
	edges: [MyTypeEdge]
	nodes: [MyType]
}

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02 🎉

Comparison is base (8596349) 95.97% compared to head (0d0ec18) 96.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1499      +/-   ##
==========================================
+ Coverage   95.97%   96.00%   +0.02%     
==========================================
  Files          51       51              
  Lines        1739     1750      +11     
==========================================
+ Hits         1669     1680      +11     
  Misses         70       70              
Impacted Files Coverage Δ
graphene/relay/connection.py 100.00% <100.00%> (ø)
graphene/types/schema.py 95.41% <0.00%> (ø)
graphene/types/inputfield.py 100.00% <0.00%> (ø)
graphene/types/argument.py 97.82% <0.00%> (+0.09%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@erikwrede erikwrede changed the title refactor: make relay type fields extendable chore: make relay type fields extendable Mar 2, 2023
@MattKleinsmith
Copy link

Thank you. This is cool.

I don't feel qualified to approve or deny, but I do like the design.

Copy link

@jendrikjoe jendrikjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So helpful going forward 👍 This will scrap a lot of workarounds from a lot of peoples codebases 🥳

graphene/relay/connection.py Show resolved Hide resolved
graphene/relay/connection.py Outdated Show resolved Hide resolved
@erikwrede erikwrede merged commit d33e38a into graphql-python:master Mar 13, 2023
@erikwrede erikwrede deleted the refactor-relay-upgradable branch March 13, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants